#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pii std::pair<int,int>
#define mkp std::make_pair
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

inline void smax(int &a, int b) {
	a = max(a, b);
}
inline void smin(int &a, int b) {
	a = min(a, b);
}

const int N = 2e3 + 7;
int n, t, a[N], col[N], ans = 0;

inline void dfs(int step) {
	if (step == n + 1) {
		int pre[2] = {-1, -1}, cur = 0;
		for (int i = 1; i <= n; ++i) {
			if (pre[col[i]] != -1 && a[i] == a[pre[col[i]]]) {
				cur += a[pre[col[i]]];
			}
			pre[col[i]] = i;
		}
		smax(ans, cur);
		return ;
	}
	col[step] = 0;
	dfs(step + 1);
	col[step] = 1;
	dfs(step + 1);
}

signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);

	std::cin >> t;
	for (int r = 1; r <= t; ++r) {
		std::cin >> n;
		ans = 0;
		for (int i = 1; i <= n; ++i) {
			std::cin >> a[i];
		}
		if (n > 15) {
			std::cout << "0\n";
			continue;
		}
		dfs(1);
		std::cout << ans << '\n';
	}


	return 0;
}